﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Diagnostics.Contracts;
using ShredTheLog.Api.DataContracts;
using System.ComponentModel.Composition;
using ShredTheLog.Api;

namespace ShredTheLog.Converters
{
    [ValueConversion(typeof(IEnumerable<Language>), typeof(IEnumerable<Language>))]
    public sealed class LanguageListSortingConverter : ConverterBase, IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var unsorted = (IEnumerable<Language>)value;
            Contract.Assume(unsorted != null);
            return LanguageListExtension.Sort(unsorted);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        public static readonly LanguageListSortingConverter Default = new LanguageListSortingConverter();
    }
}
